package mn.more.wits.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import mn.more.wits.client.ServiceInit;
import mn.more.wits.client.dto.Handshake;
import mn.more.wits.server.dao.ServiceInitDAO;
import org.apache.log4j.Logger;

public class ServiceInitImpl extends RemoteServiceServlet implements ServiceInit {

	private transient Logger logger = Logger.getLogger(ServiceInitImpl.class);
	private ServiceInitDAO dao;

	public void setDao(ServiceInitDAO dao) { this.dao = dao; }

	public Handshake init(String appName) {
		if (logger.isDebugEnabled()) { logger.debug("ServiceInitImpl.init(" + appName + ")"); }

		Handshake handshake = dao.getHandshake(appName);

		// todo-mike: hardcoded for now... need to make it proper later.
		// todo: needs to find out what this one does. :-?
		// (Mike Liu, 2008/06/22): we can use the status to show the "busy-ness" of the server
		// for example, green means system is able to handle current load, orange means server is
		// under heavy but sustainable load, and read means server is way too busy -- new clients should
		// disconnet and wait.
		handshake.setStatus(Handshake.STATUS_GREEN);

		return handshake;
	}
}
